package com.example.nyf.mapper;

import com.example.nyf.dto.SysRoleDTO;
import com.example.nyf.entity.SysRoleMenu;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface SysRoleMenuMapper {

    @Insert("insert into sys_role_menu(role_id, menu_id) values(#{role_id}, #{menu_id})")
    public int insertSysRoleMenu(SysRoleMenu sysRoleMenu);

    @Delete("<script> delete from sys_role_menu where role_id = #{role_id} and menu_id in <foreach collection='menu_id' item='id' open='(' separator=',' close=')'>#{id}</foreach> </script>")
    public int deleteSysRoleMenu(@Param("menu_id") Integer[] menu_id,  @Param("role_id") Integer role_id);

    @Delete("delete from sys_role_menu where role_id = #{role_id}")
    public int deleteSysRoleById(@Param("role_id") Integer role_id);

    @Select("select * from sys_role_menu where role_id = #{role_id}")
    public List<SysRoleMenu> listSysRoleMenu(@Param("role_id") Integer role_id);

    @Insert("<script> insert into sys_role_menu(role_id, menu_id) values " +
            "<foreach collection='menu_id' item='item' separator=','> (#{role_id}, #{item}) </foreach> </script>")
    public void insertAllSysRoleMenu(@Param("menu_id")Integer[] menu_id,  @Param("role_id") Integer role_id);
}
